"use strict";
const Service = require("egg").Service;
const jwt = require("jsonwebtoken");
class UserService extends Service {
    get User() {
        return this.app.model.User
    }
    createToken(id) {
        return jwt.sign({ id }, this.app.config.jwt.secret);
    }
    verifyToken(id) {
        return jwt.verify(id, this.app.config.jwt.secret)
    }
    async createUser(user) {
        const data = await this.User(user).save()
        const token = this.createToken(data["_id"])
        return Promise.resolve({ token, nickname: data.nickName, gender: data.gender })
    }
    async getUser(id) {
        return this.User.findById(id)
    }
}
module.exports = UserService;
